package com.niit.dao.impl;

import java.util.List;

import com.niit.bean.NoteRepo;
import com.niit.bean.User;
import com.niit.dao.NoteRepoDao;
import com.niit.utils.DbUtil;

public class NoteRepoDaoImpl implements NoteRepoDao {

	private DbUtil util =new DbUtil();
	@Override
	public int add(NoteRepo t) {
		String sql = "insert into tb_note_repo(username,repoName) values (?,?)";
		int a = util.update(sql,t.getUsername(),t.getRepoName());
		return a;
	}

	@Override
	public int delete(NoteRepo t) {
		String sql="delete from tb_note_repo where repoId=? ";
		int a=util.update(sql, t.getRepoId());
		return a;
	}

	@Override
	public int update(NoteRepo t) {
		String sql="update tb_note_repo set repoName=? where repoid=?";
		int a=util.update(sql, t.getRepoName(),t.getRepoId());
		return a;
	}

	@Override
	public int findTotal(User user) {
		String sql = "select count(*) from tb_note_repo where username=?";
		int count = util.selectCount(sql,user.getUsername());
		return count;
	}

	@Override
	public boolean isNoteRepoExist(String repoName) {
		String sql = "select count(*) from tb_note_repo where reponame=?";
		return util.selectCount(sql, repoName)>0?true:false;
	}

	@Override
	public List<NoteRepo> findReposByUser(User user) {
		String sql = "select * from tb_note_repo where username=?";
		List<NoteRepo> list =util.select(sql, NoteRepo.class,user.getUsername());
		return list;
	}

	@Override
	public int findTotal() {
		//此处该方法作废
		return 0;
	}
	
	@Override
	public List<NoteRepo> findAll(int start, int end) {
		//此处该方法作废
		return null;
	}

}
